package com.campus.service.impl;

import com.campus.dao.TeachingStudentLearningDao;
import com.campus.model.TeachingStudentLearning;
import com.campus.service.TeachingStudentLearningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TeachingStudentLearningServiceImpl implements TeachingStudentLearningService {

    @Autowired
    private TeachingStudentLearningDao teachingStudentLearningDao;

    @Override
    public boolean createTeachingStudentLearning(Integer stuInClassId, Integer unitId, String finishedStatus, Date finishedTime) {
        TeachingStudentLearning studentLearning = new TeachingStudentLearning();
        studentLearning.setStuInClassId(stuInClassId);
        studentLearning.setUnitId(unitId);
        studentLearning.setFinishedStatus(finishedStatus);
        studentLearning.setFinishedTime(finishedTime);
        return teachingStudentLearningDao.createTeachingStudentLearning(studentLearning);
    }

    @Override
    public boolean updateTeachingStudentLearning(int id, String finishedStatus, Date finishedTime) {
        TeachingStudentLearning studentLearning = new TeachingStudentLearning();
        studentLearning.setId(id);
        studentLearning.setFinishedStatus(finishedStatus);
        studentLearning.setFinishedTime(finishedTime);
        return teachingStudentLearningDao.updateTeachingStudentLearning(studentLearning);
    }

    @Override
    public boolean deleteTeachingStudentLearning(int id) {
        return teachingStudentLearningDao.deleteTeachingStudentLearning(id);
    }

    @Override
    public TeachingStudentLearning getTeachingStudentLearningById(int id) {
        return teachingStudentLearningDao.findById(id);
    }

    @Override
    public List<TeachingStudentLearning> listAllStudentLearningByUnitId(int unitId) {
        return teachingStudentLearningDao.findAllByUnitId(unitId);
    }

    @Override
    public List<TeachingStudentLearning> listAllStudentLearning() {
        return teachingStudentLearningDao.findAll();
    }
}
